/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mwt.xml.xdbforms.schemalayer.impl;

import java.util.Map;
import mwt.xml.xdbforms.schemalayer.SchemaDocument;
import mwt.xml.xdbforms.schemalayer.SchemaDocumentBuilder;
import mwt.xml.xdbforms.schemalayer.exception.SchemaBuildingException;
import mwt.xml.xdbforms.schemalayer.exception.SchemaDocumentBuilderException;

/**
 * @author Gianfranco Murador
 */
public class SchemaDocumentBuilderImpl implements SchemaDocumentBuilder {

    private SchemaNamespaceResolver nr;
    private boolean insertFKValues = true;

    public SchemaDocumentBuilderImpl() {
        nr = new SchemaNamespaceResolver();

    }

    public void addNameSpaceBinding(Map<String, String> map)
            throws SchemaDocumentBuilderException {
        if (map != null) {
            nr.addBindings(map);
        } else {
            throw new SchemaDocumentBuilderException("bindings is null");
        }
    }

    public SchemaDocument newSchemaDocument(String table,String database)
            throws SchemaDocumentBuilderException {

        try{
            SchemaDocument document = new SchemaDocumentImpl(nr);
            document.build(table,database,insertFKValues);
            return document;
        } catch (SchemaBuildingException ex) {
            throw new SchemaDocumentBuilderException(ex);
        }
    }

    public void setInsertFKValues(boolean insert) {
        insertFKValues = insert;
    }

    
}
